import Vue from 'vue'
import App from './App'
import store from './store'
import { uniCopy,getUrlParams,checkType} from '@/until/tool.js'
import { setTitle, navigateTo, isQianfan, shareFun} from '@/until/QFH5.js'
import {appLogin,getSkinType,index} from '@/api/api'
import VueCanvasPoster from 'vue-canvas-poster'
import animated from 'animate.css';
import asyncLoading from './components/asyncLoading/asyncLoading'

import asyncError from './components/asyncError/asyncError'
import './plugin/pages/myAnimation.css'


Vue.prototype.$store = store
Vue.prototype.$copy = uniCopy
Vue.prototype.$setTitle = setTitle
Vue.prototype.$navigateTo = navigateTo
Vue.prototype.$shareFun = shareFun
Vue.prototype.$checkType = checkType
Vue.config.productionTip = false
Vue.use(VueCanvasPoster)
Vue.use(animated)


Vue.component('asyncLoading',asyncLoading)
Vue.component('asyncError',asyncError)

Vue.config.ignoredElements = [...Vue.config.ignoredElements,'wx-open-launch-weapp'];
// 小程序插件中的组件，在整个项目中没有调用的话，需要在这里引用一下，否则不会被打包
// #ifdef MP-WX-PLUGIN
// #endif

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App
})
// this.$store.dispatch('setQiniuUrl','')

async function getAppStatus(){
	let obj =  getUrlParams()
	let href = location.href
	if(obj.plugin=='sports' || href.indexOf('sports')>-1){
		let res = await getSkinType({actid:obj.id})
		if(res.code==0){
			let {skin_id} = res.data
			let skin =skin_id==0?null:skin_id
			store.commit("SET_SKINTYPE",skin)
		}else{
			store.commit("SET_SKINTYPE",null)
		}
		
		
	}
	if(isQianfan()) {
		let res = await appLogin()
		let actid = obj.id || uni.getStorageSync('actid') || null
		let token = uni.getStorageSync(actid + 'bearerToken') || null
		console.log('执行结束mouted', res)
		
		if (res.code == 0) {
			//存储-------app登录活动信息；会被客户端提供的信息覆盖 异常信息请检查  qfh5.js checkLogin（）
			let data1 = Object.assign({},res.data)
			delete data1.token
			store.dispatch('setLoginInfo',data1)
			//存储
			
			if(actid!=null){
				uni.setStorageSync('actid',actid)
				uni.setStorageSync('icon'+actid,res.data.avatar)
			}
			store.commit('SETGUIDEWECHAT', true)
			store.commit('SETGUIDEPHONE', res.data.phone)
			// if(token==null){
			uni.setStorageSync(actid + 'bearerToken', res.data.token)
			uni.setStorageSync(actid + 'bearerToken_expire', res.data.expire + Date.parse(new Date()) / 1000)
			// }
			//未绑定微信
		} else if (res.code == '10012') {
			store.commit('SETGUIDEWECHAT', false)
		} else {
			// uni.showToast({title:res.text, icon:'none',duration:4000})
		}
		console.log('挂载',window.location.href)
		console.log('挂载',actid,uni.getStorageSync(actid+'token'))
		app.$mount()
	} else {
		app.$mount()
	}
}
//要使用代理
async function Index(){
	let res = await  index() 
	let siteinfo = res.data
	store.commit('SETSITEINFO',siteinfo)
	store.commit('SETQINIUURL',siteinfo.qiniu_url+'/guess')
	// store.commit("SETTASKVIDEOSTATUS",data)
	uni.setStorageSync('indexData',JSON.stringify(res.data))			 
}

Index()
getAppStatus()

